

* MASTER DO FILE FOR AIR POLLUTION COGNITION
*** updated January 2024


*******************************************
************ SET UP GLOBALS   *************
*******************************************

// replace ... with the pathname of the repository folder 
	  
global Data ".../LaNauzeSeverniniRepository/Data"
global OrigData ".../LaNauzeSeverniniRepository/OrigData"
global Results ".../LaNauzeSeverniniRepository/Results"
global doFiles ".../LaNauzeSeverniniRepository/doFiles"
	  
 

*******************************************
******IMPORTING CLEANING AND MERGING ******
*******************************************

**************
* import, merge 
**************

*** import, match users to monitors and weather stations 
do $doFiles/Import_game_data.do // creates Data/GameData.dta
do $doFiles/Import_training_dates.do // creates Data/TrainingDates.dta
do $doFiles/Import_user_data.do // creates Data/UserData.dta

do $doFiles/Import_daily_pollution.do // import daily pollution (all pollutants)
do $doFiles/Match_AQSUserData.do // match users to monitors in AQS

do $doFiles/Import_isd_us_stations.do  // import location of weather stations 
do $doFiles/Match_UserZips_ActiveIsdStations.do // match stations to users 
do $doFiles/Import_ISD_weather_data.do // import weather data (collected in two waves)
do $doFiles/Import_ISD_precip_data.do // import preciptation data 

do $doFiles/Merge_game_user.do // 

**** daily weather and pollution  
do $doFiles/Create_daily_lagged_pollution.do // generate lags of pollution for dynamic analysis
do $doFiles/Join_user_monitor_daily.do // join user data to pollution data 

do $doFiles/Create_daily_ISDweather.do // make weather data 
do $doFiles/Create_daily_lagged_weather.do // make lags of weather data
do $doFiles/Create_daily_lead_weather.do // make leads of weather data 
do $doFiles/Join_user_ISDweather_daily.do // join users data to weather data (game is zip code hour level, weather is daily) 

do $doFiles/Merge_ISDweather_pollution_users_daily.do // final merge for main dataset (game data hourly level weather and pollution daily). 

**** make datasets for Deryugina et al specification 
do $doFiles/Import_aqs_zips.do // import zips of monitors for Deryugina et al specification 
do $doFiles/Join_user_monitor_daily_inzip.do // joining data at zip level for Deryugina et al instrument 
do $doFiles/Join_pmzip_weather_game.do // merging data at user level for Deryugina et al IV estimation in R

**************
* prepare variables  
**************

do $doFiles/NormalizingScores.do // normalize scores by game
 
do $doFiles/Make_wind60IV_maxmonth.do  // create instrument 
do $doFiles/Make_wind60IV_maxmonth_lagged.do // instrument for lagged pollution 

do $doFiles/Make_ability.do // make ability measure 

do $doFiles/AQS_geocluster_seed.do // use k mean clustering to generate different size monitor groups. 






*******************************************
**************  EXHIBITS ******************
*******************************************


**********************
******* map **********
**********************


* Aggregatezips.R  // creates zip2 polygons 
* MapUsers.R // produce map of users in R 


************************
**** summary stats *****
************************


do $doFiles/summstats.do
do $doFiles/Plot_pmdistribution.do

 
**************
* main results
**************

do $doFiles/Estimate_table.do // Table 3 
do $doFiles/ForHausman.do // Table 3

do $doFiles/Estimate_otherpoll.do // Table 4 
do $doFiles/Estimate_levels.do // Figure 3

do $doFiles/Estimate_splitsampleIV.do // Table 5
do $doFiles/Estimate_splitsampleIV_time.do // Table 5
do $doFiles/Estimate_splitsampleIV_leaveone.do // Table 5

* FullIV_cluster_inzip.R // estimate Deryugina et al IV Table 6 in R  

do $doFiles/Estimate_allbyage_detail.do // Figure 4
do $doFiles/Estimate_bydomain.do // Figure 5
do $doFiles/Estimate_ability.do // Figure 6
do $doFiles/Estimate_learning.do // Figure 7 

 

**************
* appendix 
**************

do $doFiles/Appendix_Selection.do // Figure A2
do $doFiles/Estimate_byeducation.do // Figure A8
do $doFiles/Plot_agelearningcurves.do // Figure A5 
do $doFiles/Estimate_bygenderage.do // Figure A4

do $doFiles/Estimate_altgroups_seed.do // Table A1 
do $doFiles/Estimate_dynamic.do // Table A2 

*** compute first stage F stats for each regression 
do $doFiles/Compute_F_age.do // Table A3
do $doFiles/Compute_F_domain.do // Table A4
do $doFiles/Compute_F_ability.do // Table A5
do $doFiles/Compute_F_abilitybinary.do // Table A5
do $doFiles/Compute_F_learning.do // Table A6

do $doFiles/Export_apptableall.do // export full results (Table A3-A6). 

** For sharpened q values: 
* Follow instructions in $doFiles/fdr_sharpened_qvalues.do courtesy of Anderson (2007)
* Use p-values from saved results files called $doFiles/Export_apptableall.do
